import { Component, OnInit } from '@angular/core'
import { JsonApiService } from 'app/core/api/json-api.service' //http请求配置引入
import { Router } from '@angular/router' //路由引入

@Component({
  selector: 'sa-terminal-expire',
  templateUrl: './terminal-expire.component.html'
})
export class TerminalExpireComponent implements OnInit {
  tableData: any[] = [] //table数据
  totalCount: number = 0 //分页总条数
  curPage: number = 1 //分页当前页
  pageSize: number = 10 //内置的分页每页条数
  searchKey: string = '' //搜索keyword
  startTime: string = '' //过滤条件-开始时间
  endTime: string = '' // 过滤条件-结束时间

  deviceId = ''
  companyId = ''

  dateType = '2' // 时间类型: 1.下发时间;2.创建时间;3.更新时间;4.车辆到期时间
  constructor(private jsonApiService: JsonApiService, private router: Router) { }

  ngOnInit() {
    // this.load()
  }

  //公司选中车牌号回调
  companySelected(data) {
    this.deviceId = data.deviceId;
    this.companyId = data.companyId;
  }
  // 时间组件传递过来的数据
  getSelectTableTime(time) {
    this.startTime = time.startTime
    this.endTime = time.endTime
    this.load()
  }
  //表格搜索
  table_search() {
    this.curPage = 1
    this.load()
  }
  //刷新
  refresh() {
    this.load()
  }
  //初始化加载list数据
  load() {
    let data = {
      pageSize: this.pageSize,
      nowPage: this.curPage,
      parameters: {
        startTime: this.startTime,
        endTime: this.endTime,
        deviceId: this.deviceId,
        companyId: this.companyId,
        dateType: this.dateType
      }
    }
    let reqdata = 'gridPager=' + JSON.stringify(data)
    this.jsonApiService
      .http('logForDeviceEndServiceTime/pageLogForDeviceEndServiceTime.html', reqdata)
      .subscribe(data => {
        this.tableData = data.exhibitDatas
        this.totalCount = data.recordCount
      })
  }
  //分页回调
  paginate(e) {
    this.curPage = e.page + 1
    this.pageSize = e.rows
    this.load()
  }
}
